﻿
@model DroidClaim.Web.Models.ListSurveyorLocationModel
@using DroidClaim.Web.Utilities

         @using DroidClaim.Web.Mapper

@{
    ViewBag.Title = "List SurveyorLocation";
    Layout = "~/Views/Shared/_Layout.cshtml";   
 }

@section Styles {
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $("#confirm-delete").dialog({
                autoOpen: false,
                modal:true,
                resizable: false,
                buttons: {
                    Yes: function () {
                        $(this).dialog("close");
                        $.post('@Url.Action("DeleteSurveyorLocations", "SurveyorLocation")',$("#main-form").serialize(), function(data) {
                            window.location.href = '@Url.Action("ListSurveyorLocation", "SurveyorLocation")';
                        });
                    },
                    No:function(){
                        $(this).dialog("close");
                    }
                }
            });

            $("#dialog-alert").dialog({
                autoOpen: false,
                modal: true,
                buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" );
                    }
                }
            });

            $("#button-delete").on("click", function () {
                var checkboxes = $('.grid input:checkbox');
                if(checkboxes.size() == 0)
                    $("#dialog-alert").dialog("open");
                else
                {
                    var isCheck = false;
                    for(i = 0; i < checkboxes.size(); i ++)
                    {
                        isCheck = checkboxes[i].checked;
                        if(isCheck)
                            break;
                    }

                    if(!isCheck){
                        $("#dialog-alert").dialog("open");
                    }
                    else{
                        $("#confirm-delete").dialog("open");
                       
                    }
                }
            });

            $('.grid th').each(function () {
                if (this.innerHTML == "") {
                    this.innerHTML = "<input type='checkbox' id='chkHeader'  />";
                }
            });

            $('.grid th input:checkbox').click(function (e) {
                var table = $(e.target).closest('table');
                $('td input:checkbox', table).attr('checked', e.target.checked);
            });
        });

</script>
}

<h2>SurveyorLocation</h2>
@using (Html.BeginForm("ListSurveyorLocation", "SurveyorLocation", FormMethod.Post, new { @id = "main-form" }))
{
    <fieldset>
        <legend>Search</legend>
		
		<div class="texteditor">
        <label>Status</label>
            @Html.DropDownListFor(model => model.StatusSearch, StatusMapper.GetStatusSelectListWithDefault())
         </div> 
		
		<div class="texteditor">
        <label>Code</label>
		   @Html.TextBoxFor(model => model.CodeSearch)
         </div> 
		
		<div class="texteditor">
        <label>Name</label>
		   @Html.TextBoxFor(model => model.NameSearch)
         </div> 
         <div class="texteditor">
            <input type="submit" id="Search" value="Search" name="submitButton" />
        </div>
    </fieldset>

    <input type="hidden" id="hid_delete" value="Delete" name="DeleteButton" />   
    <div class="top-menu">          
        <input id="add" type="button" value="New" onclick="location.href='@Url.Action("Add", "SurveyorLocation")'"/>
        <input type="button" value="Delete" id="button-delete" />
    </div>
    <div id="confirm-delete" title="Confirm delete." style="display:none">
        <span>Do you want to delete?</span>
    </div>
    <div id="dialog-alert" title="Delete SurveyorLocation">
      <span> No item was selected.</span>
    </div>

  if (Model.ListOfSurveyorLocation != null && Model.ListOfSurveyorLocation.Count > 0)
    {
        var grid = new WebGrid(
            source: Model.ListOfSurveyorLocation, canPage: false);
        @grid.GetHtml(
        tableStyle: "tableMain grid",
        rowStyle: "row-a",
        alternatingRowStyle: "row-b",
        columns: grid.Columns(
       grid.Column(header: "", style: "width_5per", format: @<text><input name="checkbox" type="checkbox" value="@item.Id" /></text>)

 
			          ,grid.Column(header: "Status", style:  "width_100per", columnName: "Status",
                           format: item =>
                           {
                              return Utilities.GetTextFromSelectListByValue(item.Status, StatusMapper.GetStatusSelectListWithDefault());
                           }
                   )  
             ,grid.Column(header: "Latitude", canSort: false, style: "width_100per", columnName: "Latitude",
				 format: item =>
				 {
					 string Latitude = "<div class=\"word_wrap\">{0}</div>";
					 return Html.Raw(string.Format(Latitude, String.IsNullOrWhiteSpace(item.Latitude+"") ? "" : item.Latitude));
				 }
			  )
              
		            ,grid.Column(header: "Code", style: "width_100per", columnName: "Code",
			        format: item =>
				    {
                          string link = "<a href=\"{0}?Code={1}\" class=\"word_wrap\">{2}</a>";
                          return Html.Raw(string.Format(link, @Url.Content("~/SurveyorLocation/EditSurveyorLocation"), item.Code , item.Code));
				    }
			   )
		    ,grid.Column(header: "Name", style: "width_100per", columnName: "Name"
	         ,
			 format: item =>

				{
                          string link = "<a href=\"{0}?Code={1}\" class=\"word_wrap\">{2}</a>";
                          return Html.Raw(string.Format(link, @Url.Content("~/SurveyorLocation/EditSurveyorLocation"), item.Code
	  
				 , item.Name));
				}
			)
             ,grid.Column(header: "Longitude", canSort: false, style: "width_100per", columnName: "Longitude",
				 format: item =>
				 {
					 string Longitude = "<div class=\"word_wrap\">{0}</div>";
					 return Html.Raw(string.Format(Longitude, String.IsNullOrWhiteSpace(item.Longitude+"") ? "" : item.Longitude));
				 }
			  )
   
        ));
    }
    else
    {
    <div class="emptyRow">No item base on search criteria that you had inputed.</div>  
    }
}

